cmake_minimum_required(VERSION 3.20)

# 使用文件夹的名字作为项目名称
get_filename_component(folderName ${CMAKE_CURRENT_LIST_DIR} NAME)
project(${folderName} CXX)


# 库
unset(src)
aux_source_directory(src src) # 库源码
add_library(${PROJECT_NAME} OBJECT EXCLUDE_FROM_ALL ${src})
target_include_directories(${PROJECT_NAME} PUBLIC include) # 库的包含路径
# 编译器选项设置
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) # 需要C++标准
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) # 不使用C++扩展
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall>) # 设置输出所有警告(GNU)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/W4>) # 设置MSVC输出尽可能多的警告
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>) # 设置编译器utf-8编码(MSVC)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) # C++标准



# 测试程序
unset(src)
aux_source_directory(src/test src)
add_executable(Test${PROJECT_NAME} EXCLUDE_FROM_ALL ${src})
target_link_libraries(Test${PROJECT_NAME} PRIVATE ${PROJECT_NAME})
# 编译器选项设置
set_target_properties(Test${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) # 需要C++标准
set_target_properties(Test${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) # 不使用C++扩展
target_compile_options(Test${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wall>) # 设置输出所有警告(GNU)
target_compile_options(Test${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/W4>) # 设置MSVC输出尽可能多的警告
target_compile_options(Test${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>) # 设置编译器utf-8编码(MSVC)
target_compile_features(Test${PROJECT_NAME} PRIVATE cxx_std_17) # C++标准
